package com.cheyun.netsalev3.bean

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.cheyun.netsalev3.BR
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.utils.MySharedPreferences

data class Row(
        val brand: Int,
        val channel: Int,
        val customerlevel: Int,
        val customerlevelname: String,
        val dateline: String,
        val posttime: String,
        val followname: String,
        val exterior: Int,
        val exteriorname: String,
        val infoplace: Int,
        val infoplacename: String,
        val infosource: Int,
        val infosourcename: String,
        val infotype: Int,
        val infotypename: String,
        val interior: Int,
        val interiorname: String,
        val phone: String,
        val region: String,
        val series: Int,
        val seriesname: String,
        val brandname: String,
        val sex: Int,
        val spec: Int,
        val specname: String,
        val tid: Int,
        var total: Int,
        val uname: String,
        val state: String,
        val price: String? = "",
        val lastpost: String? = "",
        val ownername: String? = "",
        val hot:Int = 0,
        var xphone:String = "",
        val followstatename:String = "",
        var followstate:Int = 0,
        val followinfo:String = ""

): BaseObservable() {

    var hashMap = HashMap<String, CustomListParam>()
    var neky = ""
    /**
     * boolean 是否为潜客数据
     */
    fun setData(total: Int, neky: String, boolean: Boolean) {
        this.neky = neky
        this.total = total
        if(this.xphone.isNullOrEmpty()){
            this.xphone = this.phone
        }
        hashMap = LinkedHashMap<String, CustomListParam>()
        if (boolean) {
            hashMap["phone"] = CustomListParam("联系电话", -1, R.drawable.a01_2_xsfp_phone, "phone", xphone
                    ?: "")
            hashMap["seriesname"] = CustomListParam("首选车", -1, R.drawable.zongchexi, "seriesname", seriesname
                    ?: "")
            hashMap["dateline"] = CustomListParam("线索创建", -1, R.drawable.a01_1_zbsh_time, "dateline", dateline
                    ?: "")
        } else {
            hashMap["phone"] = CustomListParam("联系电话", -1, R.drawable.a01_2_xsfp_phone, "phone", xphone
                    ?: "")
            hashMap["ownername"] = CustomListParam("拥有者", -1, R.drawable.a01_1_zbsh_people, "ownername", ownername.toString())
            hashMap["seriesname"] = CustomListParam("首选车", -1, R.drawable.a02_3_yqlb_models, "seriesname", seriesname
                    ?: "")
            hashMap["dateline"] = CustomListParam("线索创建", -1, R.drawable.a01_1_zbsh_time, "dateline", dateline
                    ?: "")
            hashMap["infotype"] = CustomListParam("线索类型", 0, R.drawable.b01_6_zdyxsx_tos, "infotype", infotypename.toString())
            hashMap["infoplace"] = CustomListParam("触点渠道", 1, R.drawable.b01_6_zdyxsx_infobahn, "infoplace", infoplacename.toString())
            hashMap["infosource"] = CustomListParam("信息来源", 2, R.drawable.b01_6_zdyxsx_source, "infosource", infosourcename.toString())
            hashMap["brandname"] = CustomListParam("意向品牌", 3, R.drawable.b01_6_zdyxsx_brand, "brandname", brandname
                    ?: "")
            hashMap["specname"] = CustomListParam("意向车型", 4, R.drawable.b01_6_zdyxsx_models, "specname", specname
                    ?: "")
            hashMap["region"] = CustomListParam("地区", 8, R.drawable.b01_6_zdyxsx_region, "region", region
                    ?: "")
            hashMap["exteriorname"] = CustomListParam("意向车辆颜色", 5, R.drawable.b01_6_zdyxsx_vehiclecolor, "exteriorname", exteriorname
                    ?: "")
            hashMap["interiorname"] = CustomListParam("意向内饰颜色", 6, R.drawable.b01_6_zdyxsx_interiorcolor, "interiorname", interiorname
                    ?: "")
            price?.apply {
                hashMap["price"] = CustomListParam("上次报价", 7, R.drawable.b01_6_zdyxsx_lastquotation, "price", price)
            }
            changeData()
        }
    }


    /**
     * 改变data
     */
    private fun changeData() {
        var list = MySharedPreferences.getListItem()
        //默认全部为没选中
        for (d in hashMap.values) {
            d.IsSelect = false
        }
        //筛选返回数据 设置为选中
        for (cus in list) {
            hashMap[cus.key]?.IsSelect = true
        }
    }

    @get:Bindable
    var clueCustomerColumn: String = ""
        set(clueCustomerColumn) {
            field = clueCustomerColumn
            notifyPropertyChanged(BR.clueCustomerColumn)
        }

    @get:Bindable
    var isfocus: Int = 0
        set(isfocus) {
            field = isfocus
            notifyPropertyChanged(BR.isfocus)
        }
}